package com.xing.netty;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class BioServer {
    public static void main(String[] args) throws Exception{
        ServerSocket serverSocket = new ServerSocket(8888);
        while(true) {
            Socket socket = serverSocket.accept();//阻塞
            new Thread(() -> {

                InputStream inputStream;
                try {
                    inputStream = socket.getInputStream();
                    while (true) {
                        byte[] data = new byte[1024];
                        int len;
                        while((len = inputStream.read(data)) != -1) {
                            String msg = new String(data, 0, len);
                            System.out.println("客户端传来消息：" + msg);
                            socket.getOutputStream().write(data);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }).start();
            }
        }
    }

